#include "FieldMap.h"
#include <exception>
#include <string>
#include <fstream>
#include <stdexcept>

FieldMap::FieldMap(int rows, int columns)
{
    if( (rows < 0) || (columns<0) )
    {
        throw std::runtime_error("rows & cols must be >= 0");
    }

    mRows = rows;
    mColumns = columns;

    try{
        mField = new MapObject*[mRows];

        for(int i = 0; i < mRows; ++i)
        {
            mField[i] = new MapObject[mColumns];
        }
    }catch(std::bad_alloc &e){
        std::cerr << "Error allocating FieldMap matrix: " << e.what() <<std::endl;
    }
}

FieldMap::~FieldMap()
{
    if(mField)
    {
        for(int i = 0; i < mRows; ++i)
        {
            delete[] mField[i];
        }

        delete[] mField;
        mField = NULL;
    }
}

MapObject FieldMap::get(int x, int y)
{
    return mField[x][y];
}

void FieldMap::generateMap()
{
    //TODO


}
